<template>
	<uni-card v-if="settingInfo.type === 'default'" style="min-width: 375px;">
		<div slot="title" style="padding: 20px 10px;">
			<div class="space-between">
				<div style="display: flex;align-items: center;">
					<image v-if="settingInfo.logo" :src="settingInfo.logo" :style="[{height: settingInfo.detail ? '44px' : '36px', marginRight: '5px'}]" mode="heightFix"></image>
					<div>
						<CaLabel :text="settingInfo.title" title size="18" @click="onLink(settingInfo.title_link)"/>
						<CaLabel v-if="settingInfo.detail" :text="settingInfo.detail" size="14" @click="onLink(settingInfo.detail_link)"/>
					</div>
				</div>
				<CaLabel v-if="showMode" text="返回登录" title :color="core.theme.color.click" style="margin-left: 20px;" @click="e => showMode = ''"/>
			</div>
		</div>
		<block v-if="!showMode">
			<div style="display: flex;align-items: center;margin-bottom: 20px;">
				<div v-for="(mode, index) in settingInfo.modes" :key="index" class="center-column" style="margin-right: 10px;" @click="e => settingInfo.mode = mode">
					<CaLabel :text="mode" size="16" :color="settingInfo.mode === mode ? core.theme.color.normal : core.theme.color.lighter"/>
					<div :style="[{height: '5px', width: '25px', borderRadius: '2.5px', marginTop: '10px'}, settingInfo.mode === mode ? {backgroundColor: core.theme.color.click} : {}]"/>
				</div>
			</div>
		</block>
		<uni-forms ref="form" :rules="modelRules" v-model="modelValue">
			<uni-forms-item v-for="(item, index) in modelOptions" v-if="item.showAction()" :key="index" label="" :name="item.key">
				<div style="display: flex;align-items: center;">
					<uni-easyinput v-model="modelValue[item.key]" :type="item.type" :placeholder="item.placeholderAction ? item.placeholderAction() : item.placeholder" style="flex: 1;" @change="onChange($event, item.key)"/>
					<button v-if="item.key === 'phoneCode'" :loading="loadVerify" size="mini" plain :disabled="vStatus === 1 || vStatus === 2" :style="[{minWidth: '100px'}, {borderColor: vStatus === 1 || vStatus === 2 ? core.theme.color.line : core.theme.color.click}]" @click="onVerify">{{getVerifyText()}}</button>
					<button v-else-if="item.key === 'account' && showMode === '立即注册' && modelValue.account" :loading="loadExist" size="mini" plain :disabled="rightAccount || rightAccount === false" :style="[{minWidth: '100px'}, {borderColor: rightAccount || rightAccount === false ? core.theme.color.line : core.theme.color.click}]" @click="onExist">{{rightAccount === modelValue.account ? '验证通过' : rightAccount === false ? '已经存在' : '是否存在?'}}</button>
					<div v-else-if="item.key === 'imageCode'" style="width: 100px;" class="center">
						<image v-if="imageInfo.image" :src="imageInfo.image" style="width: 100px;" mode="widthFix" @click="getImageVerify"></image>
						<LoadView v-else loading="loading" noText :size="24" marginTop="0"/>
					</div>
				</div>
			</uni-forms-item>
		</uni-forms>
		<div style="width: 100%;height: 8px;"/>
		<div v-if="!showMode && settingInfo.mode === '密码登录' && (settingInfo.openRemember || settingInfo.openAutoLogin)" class="space-between">
			<div v-if="settingInfo.openRemember" style="display: flex;align-items: center;" @click="e => rememberPassword = !rememberPassword">
				<IconFont cursor="pointer" :type="rememberPassword ? 'box-yes' : 'box-no'" size="14" :color="rememberPassword ? core.theme.color.click : core.theme.color.light"/>
				<CaLabel text="记住密码" cursor="pointer" size="14" :color="rememberPassword ? core.theme.color.click : core.theme.color.light" style="margin-left: 3px;"/>
			</div>
			<div v-if="settingInfo.openAutoLogin" style="display: flex;align-items: center;" @click="e => autoLogin = !autoLogin">
				<IconFont cursor="pointer" :type="autoLogin ? 'box-yes' : 'box-no'" size="14" :color="autoLogin ? core.theme.color.click : core.theme.color.light"/>
				<CaLabel text="自动登录" cursor="pointer" size="14" :color="autoLogin ? core.theme.color.click : core.theme.color.light" style="margin-left: 3px;"/>
			</div>
		</div>
		<div v-if="showMode !== '忘记密码' && settingInfo.agreements && settingInfo.agreements.length > 0" style="display: flex;align-items: center;margin-top: 10px;" @click="e => $store.commit('setReadAgreement')">
			<IconFont cursor="pointer" :type="$store.state.readAgreement ? 'round-yes' : 'round-no'" :color="$store.state.readAgreement ? core.theme.color.click : core.theme.color.light"/>
			<div style="display: flex;align-items: center;">
				<CaLabel text="我已阅读并同意" cursor="pointer" size="12" style="margin-left: 3px;"/>
				<block v-for="(item, index) in settingInfo.agreements" :key="index">
					<CaLabel :text="item.name" cursor="pointer" size="12" :color="core.theme.color.click" cancelBubble @click="onLink(item.url)"/>
					<CaLabel :text="index === settingInfo.agreements.length - 1 ? '' : index === settingInfo.agreements.length - 2 ? '和' : '、'" cursor="pointer"/>
				</block>
			</div>
		</div>
		<button :loading="loadStatus" :disabled="loadStatus" type="primary" style="margin-top: 10px;" @click="onSubmit">{{getSubmitTitle()}}</button>
		<div slot="actions" style="margin-bottom: 24px;">
			<div v-if="!showMode" class="space-between">
				<CaLabel v-if="settingInfo.openRegister" cursor="pointer" size="12" :color="core.theme.color.click" @click="e => showMode = '立即注册'" text="立即注册"/>
				<CaLabel v-if="settingInfo.openForget" cursor="pointer" size="12" :color="core.theme.color.click" @click="e => showMode = '忘记密码'" text="忘记密码？"/>
			</div>
			<div v-if="settingInfo.footer" style="margin-top: 10px;" class="center">
				<CaLabel :text="settingInfo.footer" size="12" :color="core.theme.color.lighter" @click="onLink(settingInfo.footer_link)"/>
			</div>
		</div>
	</uni-card>
</template>

<script>
	
	import base from '@/components/index.vue'
	
	// 最长60秒倒计时
	const MaxCountdown = 60
	
	// 默认的用户信息
	const DefaultUserInfo = process.env.NODE_ENV === 'development' ? {
		phone: '18565720739',
		account: 'capfer',
		password: 'capfer1119',
		paypass: '',
		phoneCode: '',
		imageCode: '',
		invite_code: ''
		// openid: ''
	} : {}
	
	/**
	 * 登录组件 - 同时包含了注册和忘记密码。
	 * 暂不支持修改登录密码、修改支付密码
	 *
	 * 默认有电话号码登录和账号密码登录
	 * 电话登录：需要输入手机号，图片验证码，手机验证码
	 * 账号密码登录：需要输入账号，密码，图片验证码
	 * 注册：需要输入账号、手机号，图片验证码，手机验证码，密码，以及交易密码
	 * 忘记密码：需要输入手机号，图片验证码，手机验证码，密码
	 *
	 */
	
	export default {
		extends: base,
		// 处理成功后回调，父组件自行处理
		emits: ['success'],
		props: {
			// 登录类型。site：站点登录；app：前端登录
			type: {
				type: String,
				default: 'site'
			},
			// 设置信息
			settingInfo: {
				type: Object,
				default: () => {
					return {
						background: ``, // 整个页面背景
						type: 'default', // 登录样式。目前默认样式
						verson: '1.0.0', // 最新的版本号。如果版本号不一致，则提示更新
						
						logo: 'https://qiniu.capfer.cn/bmc/logo.png', // 正方形Logo。登录左边用到的logo
						logo_other: 'https://qiniu.capfer.cn/bmc/logo_other.png', // 长方形Logo。登录成功或左上角用到的logo
						name: '汽车经纪人', // 登录之后显示的名称
						title: '汽车经纪人管理站点', // 名称信息
						title_link: '', // 名称信息的超链接
						detail: '汽车经纪人管理站点', // 描述信息
						detail_link: '', // 描述信息的超链接
						footer: '汽车经纪人管理站点', // 底部信息
						footer_link: '', // 底部信息的超链接
						
						modes: ['电话登录', '密码登录'], // 允许登录的方式。phone：电话登录；password：密码登录
						mode: '电话登录', // 默认登录模式
						imageVerify: true, // 是否开启图片验证码。0或false：不需要；1或true：全都需要；2：只在密码登录时需要；3：只在电话登录时需要；4：只在注册时需要；5：只在忘记密码时需要。2345可多选成为数组
						phoneVerify: true, // 是否开启手机验证码。忘记密码、注册和电话登录时一定有，并且有图片验证码的话，则图片验证准确后才可发送手机验证码
						
						needPaypass: false, // 注册时是否需要交易密码。0或false：不需要；1或true：一定需要；2：显示需要可以没有
						needAccount: true, // 注册时是否需要账号。0或false：不需要；1或true：一定需要；2：显示需要可以没有
						needRecommend: false, // 注册时是否需要推荐人。0或false：不需要；1或true：一定需要；2：显示需要可以没有
						
						openRegister: true, // 是否开启注册
						openForget: true, // 是否开启忘记密码
						openRemember: true, // 是否开启记住密码
						openAutoLogin: true, // 是否开启自动登录
						passtype: 3, // 密码加密类型：1：base64；2：SHA256；3：AES；4：MD5
						
						agreements: [{name: '《用户协议》', url: ''}, {name: '《隐私政策》', url: ''}], // 注册时需要勾选的协议
						readAgreement: true, // 是否默认阅读了协议
					}
				}
			}
		},
		watch: {
			rememberPassword: { // 每次进来自动读取用户名和密码。该值不来自于$store，而是来自于本组件登录成功后的存储
				immediate: true,
				handler(val) {
					if (val === true || val === false) {
						this.core.storage.setData('KeyForRememberPassword', val)
						if (val) {
							if (!this.showMode && this.settingInfo.mode === '密码登录') {
								// this.core.showToast('登录成功后生效')
							}
						} else {
							// 没有记住密码，自动登录一定取消
							this.autoLogin = false
						}
					} else {
						// 初始状态下都会读取存储的用户信息。因为用户名始终是存储的
						const loginInfo = this.core.storage.getDataSync('KeyForLoginInfo')
						if (loginInfo) {
							this.modelValue.account = loginInfo.account
						}
						if (this.core.storage.getDataSync('KeyForRememberPassword') === true) {
							this.rememberPassword = true
							if (loginInfo && loginInfo.password) {
								this.password = loginInfo.password
							}
						} else {
							this.rememberPassword = false
							// 清除用户的用户名和密码
							this.core.storage.removeData('KeyForLoginInfo')
						}
					}
				}
			},
			autoLogin: { // 每次进来自动读取用户名和密码并自动登录。有用户名和密码就执行自动登录
				immediate: true,
				handler(val) {
					if (val === true || val === false) {
						this.core.storage.setData('KeyForAutoLogin', val)
					} else {
						if (this.core.storage.getData('KeyForAutoLogin') === true) {
							this.autoLogin = true
							// 如果有用户名和密码则自动登录
							this.core.delayAction(() => {
								if (!this.showMode) {
									if (this.modelValue.account && this.password) {
										this.onSubmit('密码登录')
									}
								}
							}, 1000)
						} else {
							this.autoLogin = false
						}
					}
				}
			}
		},
		data() {
			return {
				showMode: '', // 当前显示模式。为空表示登录，settingInfo.mode控制；立即注册；忘记密码
				imageInfo: {
					uuid: '', // 获取到的图片uuid
					image: '', // 获取到的图片信息
				},
				phoneInfo: {
					uuid: '', // 获取到的验证码uuid
					phone: '', // 该验证码对应的手机号。如果手机号更改了，则uuid和phone都要重新获取
					countdown: MaxCountdown,
				},
				modelValue: { // 输入框内容
					account: '',
					password: '',
					phone: '',
					paypass: '',
					phoneCode: '',
					imageCode: '',
					invite_code: ''
				},
				/**
				 * 验证码状态
				 * 0：未发送。显示发送
				 * 1：正在发送。显示发送中
				 * 2：发送成功。显示倒计时
				 * 4：发送失败。显示重新发送按钮
				 * 5：已失效。显示重新发送按钮
				 */
				vStatus: 0,
				countdown: MaxCountdown,
				
				rememberPassword: undefined, // 登录时是否勾选了记住密码
				autoLogin: undefined, // 登录时是否勾选了自动登录
				
				password: '', //加密后的登录密码。也有可能被读取存储时赋值
				
				loadVerify: false, // 验证码按钮的状态
				loadExist: false, // 检查用户名是否存在按钮的状态
				loadStatus: false, // 主按钮的状态
				
				rightAccount: '', // 验证通过的账号。空字符：初始状态；字符串：验证通过的账号；false：验证失败
			}
		},
		computed: {
			// 所有需要输入的项
			modelOptions() {
				const {settingInfo} = this
				const that = this
				return [
					{
						key: 'account',
						placeholder: '请输入账号',
						showAction() {
							if (that.showMode) {
								if (that.showMode === '立即注册') {
									return !!settingInfo.needAccount
								}
							} else {
								if (that.settingInfo.mode === '密码登录') {
									return true
								}
							}
							return false
						}
					},
					{
						key: 'phone',
						placeholder: '请输入手机号',
						showAction() {
							if (that.showMode) {
								return true
							} else {
								if (that.settingInfo.mode === '电话登录') {
									return true
								}
							}
							return false
						}
					},
					{
						key: 'password',
						type: 'password',
						placeholderAction() {
							if (that.showMode === '忘记密码') {
								return '请输入新密码'
							}
							return '请输入密码'
						},
						showAction() {
							if (that.showMode === '忘记密码') {
								return true
							}
							if (that.showMode === '立即注册') {
								// 如果需要账户名，就需要密码
								return !!settingInfo.needAccount
							}
							if (that.settingInfo.mode === '密码登录') {
								return true
							}
							return false
						}
					},
					{
						key: 'imageCode',
						placeholder: '请输入图片验证码',
						showAction() {
							if (that.settingInfo.imageVerify) {
								if (that.settingInfo.imageVerify === 1 || that.settingInfo.imageVerify === true) {
									return true
								}
								if (that.showMode === '忘记密码') {
									return that.settingInfo.imageVerify === 5 || that.settingInfo.imageVerify.include(5)
								}
								if (that.showMode === '立即注册') {
									return that.settingInfo.imageVerify === 4 || that.settingInfo.imageVerify.incude(4)
								}
								if (that.settingInfo.mode === '电话登录') {
									return that.settingInfo.imageVerify === 3 || that.settingInfo.imageVerify.incude(3)
								}
								if (that.settingInfo.mode === '密码登录') {
									return that.settingInfo.imageVerify === 2 || that.settingInfo.imageVerify.incude(2)
								}
							}
							return false
						}
					},
					{
						key: 'phoneCode',
						placeholder: '请输入手机验证码',
						showAction() {
							if (that.showMode) {
								if (that.showMode === '忘记密码') {
									return true
								}
								if (that.showMode === '立即注册') {
									return true
								}
							} else {
								if (that.settingInfo.mode === '电话登录') {
									return true
								}
							}
							return false
						}
					},
					{
						key: 'paypass',
						type: 'password',
						placeholder: '请输入支付密码', // 注册时需要
						showAction() {
							if (that.showMode) {
								if (that.showMode === '立即注册') {
									return !!that.settingInfo.needPaypass
								}
							}
							return false
						}
					},
					{
						key: 'invite_code',
						placeholder: '请输入邀请码', // 注册时需要
						showAction() {
							if (that.showMode) {
								if (that.showMode === '立即注册') {
									return !!that.settingInfo.needRecommend
								}
							}
							return false
						}
					}
				]
			},
			modelRules() {
				return {
					account: {
						rules: [
							{required: true, errorMessage: '请输入账号', trigger: 'blur'},
							{min: 3, max: 15, message: '账号长度在 3 到 15 个字符', trigger: 'blur'}
						]
					},
					password: {
						rules: [
							{required: true, errorMessage: '请输入密码', trigger: 'blur'},
							{min: 6, max: 15, errorMessage: '密码长度在 6 到 15 个字符', trigger: 'blur'},
							{pattern: /^[a-zA-Z0-9]+$/, message: '密码只能由数字和字母组成', trigger: 'blur'}
						]
					},
					phone: {
						rules: [
							{required: true, errorMessage: '请输入手机号', trigger: 'blur'},
							{pattern: /^1[3456789]\d{9}$/, errorMessage: '手机号格式不正确', trigger: 'blur'}
						]
					},
					paypass: {
						rules: [
							{required: true, errorMessage: '请输入交易密码', trigger: 'blur'},
							{min: 6, max: 15, errorMessage: '交易密码长度在 6 到 15 个字符', trigger: 'blur'},
							{pattern: /^[a-zA-Z0-9]+$/, errorMessage: '交易密码只能由数字和字母组成', trigger: 'blur'}
						]
					},
					phoneCode: {
						rules: [
							{required: true, errorMessage: '请输入手机验证码', trigger: 'blur'}
						]
					},
					imageCode: {
						rules: [
							{required: true, errorMessage: '请输入图片验证码', trigger: 'blur'}
						]
					}
				}
			}
		},
		mounted() {
			if (this.settingInfo.imageVerify) {
				this.getImageVerify()
			}
			if (this.settingInfo.readAgreement) {
				// 默认阅读了协议
				this.$store.commit('setReadAgreement', true)
			}
			Object.keys(DefaultUserInfo).forEach(key => {
				this.modelValue[key] = DefaultUserInfo[key]
			})
		},
		methods: {
			// 验证账号是否已存在
			onExist() {
				const {account} = this.modelValue
				if (!account) {
					return this.core.showToast('请输入账号')
				}
				this.loadExist = true
				this.request('siteLogin', 'account', {account}).then(res => {
					this.loadExist = false
					if (res.data) {
						this.core.showToast('账号已存在')
						this.rightAccount = false
					} else {
						this.core.showToast('账号不存在')
						this.rightAccount = account
					}
				}).catch(err => {
					this.loadExist = false
				})
			},
			// 获取图片验证码。该方法要经常刷新
			getImageVerify() {
				this.request('siteLogin', 'imageVerify', this.type, false).then(res => {
					var {uuid, captcha} = res.data
					this.imageInfo.uuid = uuid
					if (captcha.startsWith('data:image/png;base64,')) {
						this.imageInfo.image = captcha
					} else {
						// 解密后绘图
						res = this.core.synctool.secret.getPassword(captcha, this.settingInfo.passtype)
						if (res) {
							res = JSON.parse(res)
							if (res) {
								const draw = require('uniCloud-alipay/cloudfunctions/sitelogin/draw.js')
								captcha = draw(res)
							}
						}
						if (captcha.startsWith('data:image/png;base64,')) {
							this.imageInfo.image = captcha
						} else { // 其它没有base64前缀的图片
							this.imageInfo.image = `data:image/png;base64,${captcha}`
						}
					}
				})
			},
			// 判断当前是否显示了图片验证码
			showImageVerify() {
				for (let i = 0; i < this.modelOptions.length; i++) {
					if (this.modelOptions[i].key === 'imageCode') {
						return this.modelOptions[i].showAction()
					}
				}
				return false
			},
			// 获取当前类型
			getCurrentType() {
				if (this.showMode) {
					if (this.showMode === '忘记密码') {
						return 5
					}
					if (this.showMode === '立即注册') {
						return 4
					}
				} else {
					if (this.settingInfo.mode === '电话登录') {
						return 3
					}
					if (this.settingInfo.mode === '密码登录') {
						return 2
					}
				}
				return 0
			},
			// 获取手机验证码
			getPhoneVerify() {
				return new Promise((resolve, reject) => {
					this.loadVerify = true
					const {imageInfo: {uuid}, modelValue: {phone, imageCode}, type} = this
					this.request('siteLogin', 'phoneVerify', {type, uuid, phone, imageCode, verifyType: this.getCurrentType()}, false).then(res => {
						this.loadVerify = false
						this.phoneInfo = Object.assign({}, res.data)
						if (this.phoneInfo.code) {
							this.modelValue.phoneCode = this.phoneInfo.code
						}
						resolve(res)
					}).catch(err => {
						this.loadVerify = false
						this.getImageVerify()
						reject(err)
					})
				})
			},
			// 获取验证码文字
			getVerifyText() {
				const {vStatus, countdown} = this
				switch (vStatus){
					case 0:
						return '发送验证码'
					case 1:
						return '发送中...'
					case 2:
						return `${countdown}秒后重发`
					case 4:
						return '重新发送'
					case 5:
						return '重新发送'
					default:
						return '发送验证码'
				}
			},
			// 输入数据变化了。主要针对手机号和验证码
			onChange(e, type) {
				if (type === 'phone') {
					if (e && e === this.phoneInfo.phone) {
						// 验证码没变
					} else {
						// 要重新获取验证码
						this.vStatus = 0
						Object.keys(this.phoneInfo).forEach(key => {
							this.phoneInfo[key] = ''
						})
					}
				} else if (type === 'account') {
					if (e && e === this.rightAccount) {
						// 账号没变
					} else {
						// 要重新验证账号
						this.rightAccount = ''
					}
				}
			},
			// 点击了验证码按钮
			onVerify() {
				if (this.vStatus === 0 || this.vStatus === 4 || this.vStatus === 5) {
					const {imageInfo: {uuid}, modelValue: {phone, imageCode}} = this
					if (this.showImageVerify()) {
						if (!uuid) {
							return this.core.showToast('请先获取图片验证码')
						}
						if (!imageCode) {
							return this.core.showToast('请输入图片验证码')
						}
					}
					if (!phone) {
						return this.core.showToast('请输入手机号')
					}
					this.vStatus = 1
					// 获取验证码接口
					this.getPhoneVerify().then(res => {
						// 发送成功
						this.vStatus = 2
						// 开启倒计时
						this.countdown = res.data.countdown || MaxCountdown
						const cycle = () => {
							this.core.delayAction(() => {
								this.countdown--
								if (this.countdown <= 0) {
									this.vStatus = 5
								} else {
									cycle()
								}
							}, 1000)
						}
						cycle()
					}).catch(err => {
						this.vStatus = 5
					})
				}
			},
			// 点击了跳转链接
			onLink(link) {
				this.core.common.openLink(link)
			},
			// 获取提交按钮文字
			getSubmitTitle() {
				if (this.showMode) {
					if (this.showMode === '忘记密码') {
						return '重置密码'
					}
					if (this.showMode === '立即注册') {
						return '立即注册'
					}
				}
				return '登录'
			},
			// 点击了登录
			onSubmit() {
				const {modelValue: {
					account, password, phone, phoneCode, imageCode, invite_code, paypass
				}, settingInfo: {
					mode, imageVerify, phoneVerify, passtype, needPaypass, needAccount, needRecommend
				}, phoneInfo, imageInfo, showMode, rememberPassword, loadStatus} = this
				if (loadStatus) return
				this.$refs.form.validate().then(res => {
					if (this.$store.state.readAgreement) {
						const params = {type: this.type} // 请求参数
						
						const handleFetch = (type) => {
							this.loadStatus = true
							this.request('siteLogin', type, params).then(res => {
								this.$store.dispatch('handleLoginData', res.data)
								this.loadStatus = false
								// 密码登录成功后是否记住用户名和密码
								if (!showMode && mode === '密码登录') {
									// 密码被传输和存储都将加密
									const loginInfo = {account}
									if (rememberPassword) {
										// 记住密码，额外存储加密后的密码
										loginInfo.password = this.password
									}
									// 密码登录都将记住用户名
									this.core.storage.setData('KeyForLoginInfo', loginInfo)
								}
								this.$emit('success', res)
							}).catch(err => {
								this.loadStatus = false
							})
						}
						
						// 电话登录、注册、重置密码时一定有
						const mustHandle = () => {
							if (phone) {
								params.phone = phone
							} else {
								this.core.showToast('请输入电话号码')
								return false
							}
							if (!phoneInfo.uuid && phoneCode !== this.core.request.basedata.DefaultVerifyCode) {
								this.core.showToast('请发送手机验证码')
								console.log(`uuid：${phoneInfo.uuid}；验证码：${phoneCode}；默认：${this.core.request.basedata.DefaultVerifyCode}`)
								return false
							}
							params.uuid = phoneInfo.uuid
							if (!phoneCode) {
								this.core.showToast('请输入手机验证码')
								return false
							}
							params.code = phoneCode
							return true
						}
						if (showMode) {
							if (mustHandle()) {
								if (showMode === '忘记密码') {
									if (!passpass) {
										return this.core.showToast('请输入新的登录密码')
									}
									params.passpass = this.core.synctool.secret.setPassword(passpass, passtype)
									params.passtype = passtype
									// 忘记密码
									handleFetch('reset')
								} else if (showMode === '立即注册') {
									if (needAccount) {
										if (needAccount === 2) {
											// 可以没有
										} else {
											if (!account) {
												return this.core.showToast('请输入登录账号')
											}
										}
										if (account) {
											// 有账户要求则一定要密码
											if (!password) {
												return this.core.showToast('请输入登录密码')
											}
											params.password = password
											params.passtype = passtype
										}
										params.account = account
									}
									if (needRecommend) {
										if (needRecommend === 2) {
											// 可以没有
										} else {
											if (!invite_code) {
												return this.core.showToast('请输入邀请码')
											}
										}
										params.invite_code = invite_code
									}
									if (needPaypass) {
										if (needPaypass === 2) {
											// 可以没有
										} else {
											if (!paypass) {
												return this.core.showToast('请输入支付密码')
											}
										}
										if (paypass) {
											params.paypass = this.core.synctool.secret.setPassword(paypass, passtype)
										}
									}
									params.passtype = passtype
									// 立即注册
									handleFetch('register')
								}
							} else {
								return
							}
						} else {
							if (mode === '密码登录') {
								if (account) {
									params.account = account
								} else {
									return this.core.showToast('请输入用户名')
								}
								if (password) {
									this.password = this.core.synctool.secret.setPassword(password, passtype)
								} else {
									return this.core.showToast('请输入密码')
								}
								params.passtype = passtype
								params.password = this.password
								if (this.showImageVerify()) {
									if (!imageInfo.uuid) {
										return this.core.showToast('请刷新图片验证码')
									}
									if (!imageCode) {
										return this.core.showToast('请输入图片验证码')
									}
									params.code = imageCode
									params.uuid = imageInfo.uuid
								}
							} else if (mode === '电话登录') {
								if (mustHandle()) {
									// 验证通过
								} else {
									return 
								}
							}
							params.mode = mode
							handleFetch('login')
						}
					} else {
						this.core.showToast('请先同意用户协议')
					}
				})
			},
		}
	}
</script>

<style>
	.box {
		
	}
</style>